﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using Quizzer.Model;

namespace Quizzer.DataAccess
{
    public static class CourseRepository
    {
        readonly static Dictionary<Guid, Course> _courses;
        readonly static Dictionary<Guid, CourseAccount> _courseAccounts;

        static CourseRepository()
        {
            _courses = LoadCourses();
            _courseAccounts = LoadCourseAccounts();
        }

        static Dictionary<Guid, Course> LoadCourses()
        {
            return Course.Items;
        }

        static Dictionary<Guid, CourseAccount> LoadCourseAccounts()
        {
            return CourseAccount.Items;
        }

        public static ObservableCollection<Course> GetAllCourses()
        {
            return new ObservableCollection<Course>(_courses.Values.ToList());
        }

        public static ObservableCollection<Course> GetCourses(Account acc)
        {
            var query = from ca in _courseAccounts.Values
                        where ca.AccountID == acc.Id && ca.IsReadEnabled == true
                        select _courses[ca.CourseID];

            return new ObservableCollection<Course>(query.ToList());
        }

    }
}
